
package model;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;

public class ServerOnClientModel {
    
    private ArrayList<P2PThreadModel> clients;
    
    private int port;
    private ServerSocket serverSocket;
    
    public ServerOnClientModel(int port) {
        this.port = port + 1;
        clients = new ArrayList<P2PThreadModel>();
    }
    
    public boolean startConnection() {
        try {
            serverSocket = new ServerSocket(port);
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    
    public void acceptNewClient() {
        try {
            P2PThreadModel p2PThreadModel = new P2PThreadModel(
                    serverSocket.accept());
            clients.add(p2PThreadModel);
        } catch (IOException e) {
        }
    }
    
}
